﻿namespace Pottery.Module.Store.Models
{
    using System;
    using System.Data.SqlTypes;
    using System.Runtime.Serialization;
    using Pottery.Model.Infrastructure;

    /// <summary>
    /// Bill.
    /// </summary>
    [DataContract]
    public class Bill //: IValidatable, IAssignable, INullable
    {
        /*#region Constructors
        /// <summary>
        /// Default constructor. Creates an Bill with default params.
        /// </summary>
        public Bill()
        {

        }

        /// <summary>
        /// Constructor with params. Creates a new Bill. 
        /// </summary>
        /// <param name="billNumb">Bill`s number</param>
        /// <param name="billRegDate">Date of creation</param>
        /// <param name="order">Order in bill</param>
        public Bill(string billNumb, DateTime billRegDate, Order order)
        {
            mBillNumber = billNumb;
            mBillRegDate = billRegDate;
            mOrderInBill = order;
        }

        #endregion

        #region Properties
        /// <summary>
        /// Bill`s number
        /// </summary>
        [DataMember]
        public string BillNumber
        {
            get { return mBillNumber; }
            set
            {
                if (!IsNull)
                    mBillNumber = value;
            }
        }

        /// <summary>
        /// Date of creation
        /// </summary>
        [DataMember]
        public DateTime BillRegDate
        {
            get { return mBillRegDate; }
            set
            {
                if (!IsNull)
                    mBillRegDate = value;
            }
        }

        /// <summary>
        /// Order in bill
        /// </summary>
        [DataMember]
        public Order OrderInBill
        {
            get { return mOrderInBill; }
            set
            {
                if (!IsNull)
                    mOrderInBill = value;
            }
        }
        #endregion

        #region IAssignable implementation
        /// <summary>
        /// Copy data from current object to object in param.
        /// </summary>
        /// <param name="obj">object to change </param>
        public void AssignTo(object obj)
        {
            if (IsNull)
                throw new InvalidOperationException();

            if (obj == null)
                throw new ArgumentNullException();

            if (obj is Bill)
            {
                Bill bill = obj as Bill;
                bill.mBillNumber = mBillNumber;
                bill.mBillRegDate = mBillRegDate;
                bill.mOrderInBill = mOrderInBill;

                bill.mNull = false;

                return;
            }

            throw new NotSupportedException("Not supported type!");
        }
        #endregion

        #region INullable Implementation

        public bool IsNull
        {
            get { return mNull; }
        }

        public static Bill Null
        {
            get
            {
                Bill bill = new Bill();
                bill.mNull = true;
                return bill;
            }
        }

        #endregion

        #region IValidatable implementation
        /// <summary>
        /// Checks instance for data`s validity
        /// </summary>
        /// <returns>checking result</returns>
        public bool Validate()
        {
            bool isValid = true;

            if (mOrderInBill == null || mOrderInBill.IsNull)
            {
                isValid = false;
            }

            return isValid;
        }
        #endregion

        #region private Fields
        private DateTime mBillRegDate;
        private string mBillNumber;
        private Order mOrderInBill;
        private bool mNull = false;
        #endregion*/

    }
}
